<template>
  <div class="tab-control">
    <div v-for="(item,index) in title" :key="index" class="items" :class="{active:index==currentIndex}" @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>
<script>
export default {
  name:'TabControl',
  data:function(){
    return {
      currentIndex:0,
    }
  },
  props:{
    title:{
      type:Array,
      default:function(){
        return [];
      }
    }
  },
  methods: {
    itemClick:function(index){
      this.currentIndex=index;
      //传出当前点击的index
      this.$emit("tabclick",index);
    }
  },
}
</script>
<style scoped>
  .tab-control{ 
    display: flex;
    font-size: 15px;
    z-index: 9;
  }
  .tab-control .items{
    flex: 1;
    text-align: center;
    height: 40px;
    line-height: 40px;
    
  }
  .tab-control .items span{
    padding:5px;
  }
  .active{
    color:var(--color-high-text) ;
  }
  .active span{
    border-bottom: 3px solid var(--color-tint);
  }
</style>